import CounterStore from "./counterStore"
import { createContext, useContext } from 'react'

class RootStore {
  constructor() {
    this.counterStore = new CounterStore()
  }
}
const rootStore = new RootStore()
const RootStoreContext = createContext()
export const RootStoreProvider = ({ children }) => {
  return (
    // 将rootStore传递给provider，这样所有被provider包裹的组件都能通过useContext使用到rootStore
    <RootStoreContext.Provider value={rootStore}>
      {children}
    </RootStoreContext.Provider>
  )
}
// 通过useContext，将RootStoreContext导出
export const useRootStore = () => {
  console.log(useContext(RootStoreContext))
  return useContext(RootStoreContext)
}